package com.rockxin.cat.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockxin.cat.R;
import com.rockxin.cat.adapter.PagerAdapter;
import com.rockxin.cat.base.BaseActivity;
import com.rockxin.cat.customview.NoScrollViewPager;
import com.rockxin.cat.fragment.RedPacketFragment;
import com.rockxin.cat.fragment.RedPacketListFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我的红包
 */
public class MyRedPacketActivity extends BaseActivity {

    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.cashCoupon)
    TextView cashCoupon;
    @BindView(R.id.raiseCoupon)
    TextView raiseCoupon;
    @BindView(R.id.cashBag)
    TextView cashBag;
    @BindView(R.id.viewPager)
    NoScrollViewPager viewPager;

    private MyRedPacketActivity myRedPacketActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myRedPacketActivity = this;
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_my_red_packet;
    }

    @Override
    public void initData() {
        title.setText("我的红包");
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(RedPacketFragment.newInstance(3));
        fragmentList.add(RedPacketFragment.newInstance(1));
        fragmentList.add(RedPacketFragment.newInstance(2));
        viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager(), fragmentList));
        viewPager.setOffscreenPageLimit(fragmentList.size());
        viewPager.setCurrentItem(0);
        viewPager.setNoScroll(true);
    }


    @OnClick({R.id.back_img, R.id.cashCoupon, R.id.raiseCoupon, R.id.cashBag})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.cashCoupon:
                setDefaultState();
                cashCoupon.setTextColor(ContextCompat.getColor(myRedPacketActivity, R.color.colorMoney));
                viewPager.setCurrentItem(0);
                break;
            case R.id.raiseCoupon:
                setDefaultState();
                raiseCoupon.setTextColor(ContextCompat.getColor(myRedPacketActivity, R.color.colorMoney));
                viewPager.setCurrentItem(1);
                break;
            case R.id.cashBag:
                setDefaultState();
                cashBag.setTextColor(ContextCompat.getColor(myRedPacketActivity, R.color.colorMoney));
                viewPager.setCurrentItem(2);
                break;
        }
    }

    private void setDefaultState() {
        raiseCoupon.setTextColor(ContextCompat.getColor(myRedPacketActivity, R.color.colorTextColor));
        cashCoupon.setTextColor(ContextCompat.getColor(myRedPacketActivity, R.color.colorTextColor));
        cashBag.setTextColor(ContextCompat.getColor(myRedPacketActivity, R.color.colorTextColor));
    }
}
